package com.wk.wanjetpack.viewmodels

import android.app.Application
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.ExperimentalPagingApi
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.wk.wanjetpack.bean.Article
import com.wk.wanjetpack.net.MainRepo
import kotlinx.coroutines.flow.Flow

/**
 * @author peng
 * @date 2021/1/20
 * 说明
 */

class MainViewModel @ViewModelInject constructor(
    application: Application,
    private val repo: MainRepo
) : AndroidViewModel(application) {

//    private val _listDataLiveData: MutableLiveData<List<Chapters>> = MutableLiveData()
//
//    val listDataLiveData: LiveData<List<Chapters>>
//        get() {
//            return _listDataLiveData
//        }

    @ExperimentalPagingApi
    fun requestListData(): Flow<PagingData<Article>> {
        return repo.getArticles().cachedIn(viewModelScope)
    }

}